package cn.wolfcode.education.service.impl;

import cn.wolfcode.education.domain.SystemDictionary;
import cn.wolfcode.education.domain.SystemDictionaryItem;
import cn.wolfcode.education.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.education.mapper.SystemDictionaryMapper;
import cn.wolfcode.education.service.ISystemDictionaryService;
import cn.wolfcode.education.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {
    @Autowired
    private SystemDictionaryMapper systemDictionarymapper;
    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    public List<SystemDictionaryItem> getSystemDictionaryItem(Long id) {
        return systemDictionaryItemMapper.getSystemDictionaryItem(id);
    }

    public PageResult getSystemDictionary() {
        int count = systemDictionarymapper.getCount();
        if (count == 0){
            return new PageResult();
        }
        List<SystemDictionary> list = systemDictionarymapper.selectAll();
        return new PageResult(count,list);
    }

    public PageResult getSystemDictionaryItemToPageRestult(Long parentId) {
        int total = systemDictionaryItemMapper.getSystemDictionaryItemCount(parentId);
        if (total == 0){
            return new PageResult();
        }
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.getSystemDictionaryItem(parentId);
        return new PageResult(total,list);
    }

    public List<SystemDictionary> selectAll() {
        return systemDictionarymapper.selectAll();
    }

    public void save(SystemDictionary systemDictionary) {
        systemDictionarymapper.insert(systemDictionary);
    }

    public void delete(Long id) {
        systemDictionarymapper.deleteByPrimaryKey(id);
    }

    public void update(SystemDictionary systemDictionary) {
        systemDictionarymapper.updateByPrimaryKey(systemDictionary);
    }

    public void saveitem(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.insert(systemDictionaryItem);
    }

    public void deleteitem(Long id) {
        systemDictionaryItemMapper.delete(id);
    }

    public void updateitme(SystemDictionaryItem systemDictionaryItem) {
        systemDictionaryItemMapper.update(systemDictionaryItem);
    }
}
